home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 022 / lemacs / vmsvt.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  5KB  |  277 lines

  1. /*
  2.  *  VMS terminal handling routines
  3.  *
  4.  *  Known types are:
  5.  *    VT52, VT100, and UNKNOWN (which is defined to be an ADM3a)
  6.  *    written by Curtis Smith
  7.  */
  8.  
  9. #include        <stdio.h>
  10. #include        "estruct.h"
  11. #include    "edef.h"
  12.  
  13. #if     VMSVT
  14.  
  15. #define    termdef    1            /* don't define "term" external */
  16.  
  17. #include <ssdef.h>        /* Status code definitions        */
  18. #include <descrip.h>        /* Descriptor structures        */
  19. #include <iodef.h>        /* IO commands                */
  20. #include <ttdef.h>        /* tty commands                */
  21.  
  22. extern  int     ttopen();               /* Forward references.          */
  23. extern  int     ttgetc();
  24. extern  int     ttputc();
  25. extern  int     ttflush();
  26. extern  int     ttclose();
  27. extern  int    vmsopen();
  28. extern  int    vmseeol();
  29. extern  int    vmseeop();
  30. extern  int    vmsbeep();
  31. extern  int    vmsmove();
  32. extern    int    vmsrev();
  33. extern  int    eolexist;
  34.  
  35. #define    NROWS    24            /* # of screen rolls        */
  36. #define    NCOLS    80            /* # of screen columns        */
  37. #define    MARGIN    8            /* size of minimim margin and    */
  38. #define    SCRSIZ    64            /* scroll size for extended lines */
  39.  
  40. /*
  41.  * Dispatch table. All the
  42.  * hard fields just point into the
  43.  * terminal I/O code.
  44.  */
  45. TERM    term    = {
  46.     NROWS - 1,
  47.     NCOLS,
  48.     MARGIN,
  49.     SCRSIZ,
  50.         &vmsopen,
  51.         &ttclose,
  52.         &ttgetc,
  53.         &ttputc,
  54.         &ttflush,
  55.         &vmsmove,
  56.         &vmseeol,
  57.         &vmseeop,
  58.         &vmsbeep,
  59.         &vmsrev
  60. };
  61.  
  62. char * termeop;            /* Erase to end of page string        */
  63. int eoppad;            /* Number of pad characters after eop    */
  64. char * termeol;            /* Erase to end of line string        */
  65. int eolpad;            /* Number of pad characters after eol    */
  66. char termtype;            /* Terminal type identifier        */
  67.  
  68.  
  69. /*******
  70.  *  ttputs - Send a string to ttputc
  71.  *******/
  72.  
  73. ttputs(string)
  74. char * string;
  75. {
  76.     while (*string != '\0')
  77.         ttputc(*string++);
  78. }
  79.  
  80.  
  81. /*******
  82.  *  vmspad - Pad the output after an escape sequence
  83.  *******/
  84.  
  85. vmspad(count)
  86. int count;
  87. {
  88.     while (count-- > 0)
  89.         ttputc('\0');
  90. }
  91.  
  92.  
  93. /*******
  94.  *  vmsmove - Move the cursor
  95.  *******/
  96.  
  97. vmsmove(row, col)
  98. {
  99.     switch (termtype) {
  100.         case TT$_UNKNOWN:
  101.             ttputc('\033');
  102.             ttputc('=');
  103.             ttputc(row+' ');
  104.             ttputc(col+' ');
  105.             break;
  106.         case TT$_VT52:
  107.             ttputc('\033');
  108.             ttputc('Y');
  109.             ttputc(row+' ');
  110.             ttputc(col+' ');
  111.             break;
  112.         case TT$_VT100:
  113.             {
  114.                 char buffer[24];
  115.  
  116.                 sprintf(buffer, "\033[%d;%dH", row+1, col+1);
  117.                 ttputs(buffer);
  118.                 vmspad(50);
  119.             }
  120.     }
  121. }
  122.  
  123. /*******
  124.  *  vmsrev - set the reverse video status
  125.  *******/
  126.  
  127. vmsrev(status)
  128.  
  129. int status;    /* TRUE = reverse video, FALSE = normal video */
  130. {
  131.     switch (termtype) {
  132.         case TT$_UNKNOWN:
  133.             break;
  134.         case TT$_VT52:
  135.             break;
  136.         case TT$_VT100:
  137.             if (status) {
  138.                 ttputc('\033');
  139.                 ttputc('[');
  140.                 ttputc('7');
  141.                 ttputc('m');
  142.             } else {
  143.                 ttputc('\033');
  144.                 ttputc('[');
  145.                 ttputc('m');
  146.             }
  147.             break;
  148.     }
  149. }
  150.  
  151. /*******
  152.  *  vmseeol - Erase to end of line
  153.  *******/
  154.  
  155. vmseeol()
  156. {
  157.     ttputs(termeol);
  158.     vmspad(eolpad);
  159. }
  160.  
  161.  
  162. /*******
  163.  *  vmseeop - Erase to end of page (clear screen)
  164.  *******/
  165.  
  166. vmseeop()
  167. {
  168.     ttputs(termeop);
  169.     vmspad(eoppad);
  170. }
  171.  
  172.  
  173. /*******
  174.  *  vmsbeep - Ring the bell
  175.  *******/
  176.  
  177. vmsbeep()
  178. {
  179.     ttputc('\007');
  180. }
  181.  
  182.  
  183. /*******
  184.  *  vmsopen - Get terminal type and open terminal
  185.  *******/
  186.  
  187. vmsopen()
  188. {
  189.     termtype = vmsgtty();
  190.     switch (termtype) {
  191.         case TT$_UNKNOWN:    /* Assume ADM3a    */
  192.             eolexist = FALSE;
  193.             termeop = "\032";
  194.             eoppad = 0;
  195.             break;
  196.         case TT$_VT52:
  197.             termeol = "\033K";
  198.             eolpad = 0;
  199.             termeop = "\033H\033J";
  200.             eoppad = 0;
  201.             break;
  202.         case TT$_VT100:
  203.             revexist = TRUE;
  204.             termeol = "\033[K";
  205.             eolpad = 3;
  206.             termeop = "\033[;H\033[2J";
  207.             eoppad = 50;
  208.             break;
  209.         default:
  210.             puts("Terminal type not supported");
  211.             exit (SS$_NORMAL);
  212.     }
  213.         ttopen();
  214. }
  215.  
  216.  
  217. struct iosb {            /* I/O status block            */
  218.     short    i_cond;        /* Condition value            */
  219.     short    i_xfer;        /* Transfer count            */
  220.     long    i_info;        /* Device information            */
  221. };
  222.  
  223. struct termchar {        /* Terminal characteristics        */
  224.     char    t_class;    /* Terminal class            */
  225.     char    t_type;        /* Terminal type            */
  226.     short    t_width;    /* Terminal width in characters        */
  227.     long    t_mandl;    /* Terminal's mode and length        */
  228.     long    t_extend;    /* Extended terminal characteristics    */
  229. };
  230.  
  231. /*******
  232.  *  vmsgtty - Get terminal type from system control block
  233.  *******/
  234.  
  235. vmsgtty()
  236. {
  237.     short fd;
  238.     int status;
  239.     struct iosb iostatus;
  240.     struct termchar tc;
  241.     $DESCRIPTOR(devnam, "SYS$INPUT");
  242.  
  243.     status = sys$assign(&devnam, &fd, 0, 0);
  244.     if (status != SS$_NORMAL)
  245.         exit (status);
  246.  
  247.     status = sys$qiow(        /* Queue and wait        */
  248.         0,            /* Wait on event flag zero    */
  249.         fd,            /* Channel to input terminal    */
  250.         IO$_SENSEMODE,        /* Get current characteristic    */
  251.         &iostatus,        /* Status after operation    */
  252.         0, 0,            /* No AST service        */
  253.         &tc,            /* Terminal characteristics buf    */
  254.         sizeof(tc),        /* Size of the buffer        */
  255.         0, 0, 0, 0);        /* P3-P6 unused            */
  256.  
  257.                     /* De-assign the input device    */
  258.     if (sys$dassgn(fd) != SS$_NORMAL)
  259.         exit(status);
  260.  
  261.     if (status != SS$_NORMAL)    /* Jump out if bad status    */
  262.         exit(status);
  263.     if (iostatus.i_cond != SS$_NORMAL)
  264.         exit(iostatus.i_cond);
  265.  
  266.     return tc.t_type;        /* Return terminal type        */
  267. }
  268.  
  269. #else
  270.  
  271. hellovms()
  272.  
  273. {
  274. }
  275.  
  276. #endif    VMSVT
  277.